from hjl_spider.stockpile.base import StockpileBase


class DataFile(StockpileBase):
    '''
     基础数据类
    '''
    Filed = "Data_None"  # 特征类

    def __init__(self, **kwargs):
        '''
        初始化, 函数, 并且默认几个用户值
        :param kwargs: {"key":"new_values"}
        '''
        self.data_map()
        for key, value in kwargs.items():
            if self.get(key, False) is None:  # 判断只添加存在的类属性
                self[key] = value
        StockpileBase.__init__(self)

    def get_data(self, obj, *args, **kwargs) -> None:
        '''
        添加
        :param obj: 带数据描述的对象
        :return: None
        '''
        pass

    def data_map(self, *args, **kwargs) -> None:
        '''
        映射用户的值到data数据字典储存中
        :param args:
        :param kwargs:
        :return:
        '''

        dict_key = dir(self)
        for i in dict_key:  # 全部属性
            if not (i == "Filed"):
                if getattr(self, i) == self.Filed:  # 筛选出用户定义的
                    self[i] = None

